﻿package plugin.activity.newComponent
{
    import cmd.*;
    import com.core.*;
    import flash.display.*;
    import flash.events.*;
    import manager.*;
    import morn.core.components.*;
    import plugin.activity.*;
    import view.message.*;
    import view.mornExtends.*;

    public class NewRiLiItem extends Sprite
    {
        private var item:FlashItem;
        private var gouImg:Image;
        private var todayImg:Image;
        private var btn_bu:Image;
        private var img1:Image;
        private var img2:Image;
        private var _data:Object;

        public function NewRiLiItem()
        {
            this.init();
            return;
        }// end function

        private function init() : void
        {
            this.img1 = new Image();
            this.img1.url = "png.activity.1";
            this.img1.x = 10;
            this.img1.y = 6;
            this.addChild(this.img1);
            this.img2 = new Image();
            this.img2.url = "png.activity.8";
            this.img2.x = 20;
            this.img2.y = 6;
            this.addChild(this.img2);
            this.todayImg = new Image();
            this.todayImg.url = "png.activity.today";
            this.todayImg.x = 50;
            this.todayImg.y = 2;
            this.todayImg.visible = false;
            this.addChild(this.todayImg);
            this.gouImg = new Image();
            this.gouImg.url = "png.activity.yqiand";
            this.gouImg.x = 18;
            this.gouImg.width = 41;
            this.gouImg.height = 28;
            this.gouImg.visible = false;
            this.addChild(this.gouImg);
            this.btn_bu = new Image();
            this.btn_bu.url = "png.activity.buqian";
            this.btn_bu.x = 39;
            this.btn_bu.y = 2;
            this.btn_bu.visible = false;
            this.btn_bu.addEventListener(MouseEvent.CLICK, this.onBuQian);
            this.addChild(this.btn_bu);
            return;
        }// end function

        private function onBuQian(event:MouseEvent) : void
        {
            var e:* = event;
            var vipdata:* = ModelProxy.getValue("vip", "getvip");
            if (vipdata.leftSignCount == 0)
            {
                Alert2.show("免费补签次数不足", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    ModelProxy.change("movetips", "error", "免费补签次数不足");
                }
                return;
            }// end function
            );
            }
            else
            {
                Alert2.show("是否消耗一次免费补签次数？", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                if (param1 == 0)
                {
                    PluginManager.instance.sendToServer("activity", CMDActivity.QianDao, {today:_data.date, type:1});
                }
                return;
            }// end function
            );
            }
            return;
        }// end function

        private function gotoQD() : void
        {
            var yuanbao:int;
            if (!NewActivityUICtrl.isShow)
            {
                Alert2.show("确定花费 100 元宝用来补签一次吗？", "", ["确定", "取消"], function (param1:int, param2:Object) : void
            {
                var _loc_3:int = 0;
                if (param1 == 0)
                {
                    _loc_3 = UserData.getBagData("money");
                    if (_loc_3 >= 100)
                    {
                        PluginManager.instance.sendToServer("activity", CMDActivity.QianDao, {today:_data.date, type:1});
                    }
                    else
                    {
                        ModelProxy.change("movetips", "error", "你的元宝不足");
                    }
                }
                else if (param1 == 100)
                {
                    NewActivityUICtrl.isShow = true;
                    gotoQD();
                }
                return;
            }// end function
            );
            }
            else
            {
                yuanbao = UserData.getBagData("money");
                if (yuanbao >= 100)
                {
                    PluginManager.instance.sendToServer("activity", CMDActivity.QianDao, {today:this._data.date, type:1});
                }
                else
                {
                    ModelProxy.change("movetips", "error", "你的元宝不足");
                }
            }
            return;
        }// end function

        public function get data() : Object
        {
            return this._data;
        }// end function

        public function set data(param1:Object) : void
        {
            var _loc_4:String = null;
            var _loc_5:String = null;
            var _loc_6:String = null;
            this._data = param1;
            var _loc_2:* = this._data.day;
            var _loc_3:* = this._data.date;
            if (_loc_3 > 9)
            {
                _loc_4 = _loc_3.toString();
                _loc_5 = _loc_4.substr(0, 1);
                _loc_6 = _loc_4.substr(1, 1);
                this.img1.url = "png.activity." + _loc_5;
                this.img2.url = "png.activity." + _loc_6;
                this.img2.visible = true;
            }
            else
            {
                this.img2.visible = false;
                this.img1.url = "png.activity." + _loc_3.toString();
            }
            return;
        }// end function

        public function setToday() : void
        {
            this.todayImg.visible = true;
            return;
        }// end function

        public function setBuQian() : void
        {
            this.btn_bu.visible = true;
            return;
        }// end function

        public function setYiQian() : void
        {
            this.gouImg.visible = true;
            return;
        }// end function

    }
}
